﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BLL;
using Model;
using System.Web.Security;

namespace OA.Controllers
{
    public class RollInfoController : Controller
    {
        //
        // GET: /RollInfo/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult RollInfo()
        {
            if (!System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return Content("<script>window.parent.location.href='/Login/Login';</script>");
            }
            Admin_Role();
            RoleUpdate();
            string RoleId = (System.Web.HttpContext.Current.User.Identity as FormsIdentity).Ticket.UserData;
            ViewData["RoleId"] = RoleId;
            return View();
        }
        public ActionResult editRole()
        {
            string RoleId = (System.Web.HttpContext.Current.User.Identity as FormsIdentity).Ticket.UserData;
            if (RoleId != "13") {
                return Content("<script>alert('只有系统管理员才能编辑权限');window.parent.location.href='/RollInfo/RollInfo'; parent.layer.close(parent.layer.getFrameIndex())</script>");
            }
            RoleUpdate();
            return View();
        }
        [HttpPost]
        public ActionResult editRole(FormCollection fc)
        {
              string memberConsume= fc["memberConsume"] ;
              string memberRecharge = fc["memberRecharge"];
              string memberAdd =fc["memberAdd"];
              string changeCardPwd =fc["changeCardPwd"];
              string memberSelect =fc["memberSelect"];
              string lostCard =fc["lostCard"] ;
              string lockSystem =fc["lock"];
              string balanceRemind =fc["balanceRemind"];
              string birthdayRemind =fc["birthdayRemind"];
              string userManager =fc["userManager"];
              string inputExcel =fc["inputExcel"];
              string email = fc["email"];
              string cardDesign = fc["cardDesign"];
              string memeberLevel = fc["memeberLevel"];
              string Produce = fc["Produce"];
              string opeatorManager = fc["opeatorManager"];
              string zhinengjuece = fc["zhinengjuece"];
              string roleManger = fc["roleManger"];
              string consumerManager = fc["consumerManager"];
              string usergongxian = fc["usergongxian"];
              string goodsSelect = fc["goodsSelect"];
              string memberCount = fc["memberCount"];
              string ageAnalyse = fc["ageAnalyse"];
              string goodsPie = fc["goodsPie"];
              string systemLog = fc["systemLog"];
              string userWater = fc["userWater"];
              string consumeWater = fc["consumeWater"];
              string goodsWater = fc["goodsWater"];
              string discountSelect = fc["discountSelect"];
              string card = fc["card"];
              string Acard = fc["Acard"];
              string wash = fc["wash"];
              string delContent = fc["delContent"];

              string str ="",str1="",str2="",str3="",str4="",str5="",str6="";
              if (memberConsume == "false")
              {
                  str = "0,";
              }
              else {
                  str = "1,";
              }
              if (memberRecharge == "false")
              {
                  str +="0,";
              }
              else
              {
                  str += "1,";
              }
              if (memberAdd == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (changeCardPwd == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (memberSelect == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (lostCard == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (lockSystem == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (balanceRemind == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (birthdayRemind == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (userManager == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (inputExcel == "false")
              {
                  str += "0,";
              }
              else
              {
                  str += "1,";
              }
              if (email == "false")
              {
                  str += "0";
              }
              else
              {
                  str += "1";
              }
              if (cardDesign == "false")
              {
                  str1 += "0,";
              }
              else
              {
                  str1 += "1,";
              }
              if (memeberLevel == "false")
              {
                  str1 += "0,";
              }
              else
              {
                  str1 += "1,";
              }
              if (Produce == "false")
              {
                  str1 += "0";
              }
              else
              {
                  str1 += "1";
              }
              if (opeatorManager == "false")
              {
                  str2 += "0,";
              }
              else
              {
                  str2 += "1,";
              }
              if (zhinengjuece == "false")
              {
                  str2 += "0,";
              }
              else
              {
                  str2 += "1,";
              }
              if (roleManger == "false")
              {
                  str2 += "0";
              }
              else
              {
                  str2 += "1";
              }
              if (consumerManager == "false")
              {
                  str3 += "0,";
              }
              else
              {
                  str3 += "1,";
              }
              if (usergongxian == "false")
              {
                  str3 += "0,";
              }
              else
              {
                  str3 += "1,";
              }
              if (goodsSelect == "false")
              {
                  str3 += "0,";
              }
              else
              {
                  str3 += "1,";
              }
              if (memberCount == "false")
              {
                  str3 += "0,";
              }
              else
              {
                  str3 += "1,";
              }
              if (ageAnalyse == "false")
              {
                  str3 += "0,";
              }
              else
              {
                  str3 += "1,";
              }
              if (goodsPie == "false")
              {
                  str3 += "0";
              }
              else
              {
                  str3 += "1";
              }
              if (systemLog == "false")
              {
                  str4 += "0,";
              }
              else
              {
                  str4 += "1,";
              }
              if (userWater == "false")
              {
                  str4 += "0,";
              }
              else
              {
                  str4 += "1,";
              }
              if (consumeWater == "false")
              {
                  str4 += "0,";
              }
              else
              {
                  str4 += "1,";
              }
              if (goodsWater == "false")
              {
                  str4 += "0,";
              }
              else
              {
                  str4 += "1,";
              }
              if (discountSelect == "false")
              {
                  str4 += "0";
              }
              else
              {
                  str4 += "1";
              }
              if (card == "false")
              {
                  str5 += "0,";
              }
              else
              {
                  str5 += "1,";
              }
              if (Acard == "false")
              {
                  str5 += "0,";
              }
              else
              {
                  str5 += "1,";
              }
              if (wash == "false")
              {
                  str5 += "0,";
              }
              else
              {
                  str5 += "1,";
              }
              if (delContent == "false")
              {
                  str5 += "0";
              }
              else
              {
                  str5 += "1";
              }
              roleInfo RI = new roleInfo();
              roleInfoManager RIManager = new roleInfoManager();
              List<roleInfo> list= RIManager.GetAll().ToList();
              list[1].roleInfo1 = str;
              list[1].roleInfo2 = str1;
              list[1].roleInfo3 = str2;
              list[1].roleInfo4 = str3;
              list[1].roleInfo5 = str4;
              list[1].roleInfo6 = str5;
              RIManager.Update();
              return Content("<script>alert('更新成功');window.parent.location.href='/RollInfo/RollInfo'; parent.layer.close(parent.layer.getFrameIndex())</script>");
        }

        public void RoleUpdate()
        {
            roleInfo RI = new roleInfo();
            roleInfoManager RIManager = new roleInfoManager();
            List<roleInfo> listRole = RIManager.GetAll().ToList();
            #region 普通管理员
            string[] roleInfo1 = listRole[1].roleInfo1.ToString().Split(',');
            string[] roleInfo2 = listRole[1].roleInfo2.ToString().Split(',');
            string[] roleInfo3 = listRole[1].roleInfo3.ToString().Split(',');
            string[] roleInfo4 = listRole[1].roleInfo4.ToString().Split(',');
            string[] roleInfo5 = listRole[1].roleInfo5.ToString().Split(',');
            string[] roleInfo6 = listRole[1].roleInfo6.ToString().Split(',');
            for (int i = 0; i < roleInfo1.Count(); i++)
            {
                if (roleInfo1[0] == "1")
                {
                    ViewData["memberConsume"] = true;
                }
                if (roleInfo1[1] == "1")
                {
                    ViewData["memberRecharge"] = true;
                }
                if (roleInfo1[2] == "1")
                {
                    ViewData["memberAdd"] = true;
                }
                if (roleInfo1[3] == "1")
                {
                    ViewData["changeCardPwd"] = true;
                }
                if (roleInfo1[4] == "1")
                {
                    ViewData["memberSelect"] = true;
                }
                if (roleInfo1[5] == "1")
                {
                    ViewData["lostCard"] = true;
                }
                if (roleInfo1[6] == "1")
                {
                    ViewData["lock"] = true;
                }
                if (roleInfo1[7] == "1")
                {
                    ViewData["balanceRemind"] = true;
                }
                if (roleInfo1[8] == "1")
                {
                    ViewData["birthdayRemind"] = true;
                }
                if (roleInfo1[9] == "1")
                {
                    ViewData["userManager"] = true;
                }
                if (roleInfo1[10] == "1")
                {
                    ViewData["inputExcel"] = true;
                }
                if (roleInfo1[11] == "1")
                {
                    ViewData["email"] = true;
                }
            }

            for (int i = 0; i < roleInfo2.Count(); i++)
            {
                if (roleInfo2[0] == "1")
                {
                    ViewData["cardDesign"] = true;
                }
                if (roleInfo2[1] == "1")
                {
                    ViewData["memeberLevel"] = true;
                }
                if (roleInfo2[2] == "1")
                {
                    ViewData["Produce"] = true;
                }

            }
            for (int i = 0; i < roleInfo3.Count(); i++)
            {
                if (roleInfo3[0] == "1")
                {
                    ViewData["opeatorManager"] = true;
                }
                if (roleInfo3[1] == "1")
                {
                    ViewData["zhinengjuece"] = true;
                }
                if (roleInfo3[2] == "1")
                {
                    ViewData["roleManger"] = true;
                }

            }
            for (int i = 0; i < roleInfo4.Count(); i++)
            {
                if (roleInfo4[0] == "1")
                {
                    ViewData["consumerManager"] = true;
                }
                if (roleInfo4[1] == "1")
                {
                    ViewData["usergongxian"] = true;
                }
                if (roleInfo4[2] == "1")
                {
                    ViewData["goodsSelect"] = true;
                }
                if (roleInfo4[3] == "1")
                {
                    ViewData["memberCount"] = true;
                }
                if (roleInfo4[4] == "1")
                {
                    ViewData["ageAnalyse"] = true;
                }
                if (roleInfo4[5] == "1")
                {
                    ViewData["goodsPie"] = true;
                }

            }
            for (int i = 0; i < roleInfo5.Count(); i++)
            {
                if (roleInfo5[0] == "1")
                {
                    ViewData["systemLog"] = true;
                }
                if (roleInfo5[1] == "1")
                {
                    ViewData["userWater"] = true;
                }
                if (roleInfo5[2] == "1")
                {
                    ViewData["consumeWater"] = true;
                }
                if (roleInfo5[3] == "1")
                {
                    ViewData["goodsWater"] = true;
                }
                if (roleInfo5[4] == "1")
                {
                    ViewData["discountSelect"] = true;
                }

            }
            for (int i = 0; i < roleInfo6.Count(); i++)
            {
                if (roleInfo6[0] == "1")
                {
                    ViewData["card"] = true;
                }
                if (roleInfo6[1] == "1")
                {
                    ViewData["Acard"] = true;
                }
                if (roleInfo6[2] == "1")
                {
                    ViewData["wash"] = true;
                }
                if (roleInfo6[3] == "1")
                {
                    ViewData["delContent"] = true;
                }
            }

            #endregion
        }
        public void Admin_Role()
        {
            roleInfo RI = new roleInfo();
            roleInfoManager RIManager = new roleInfoManager();
            List<roleInfo> listRole = RIManager.GetAll().ToList();
            ViewData["Admin_roleName"] = listRole[0].roleName;
            ViewData["roleName"] = listRole[1].roleName;
            #region 系统管理员
            string[] Admin_roleInfo1 = listRole[0].roleInfo1.ToString().Split(',');
            string[] Admin_roleInfo2 = listRole[0].roleInfo2.ToString().Split(',');
            string[] Admin_roleInfo3 = listRole[0].roleInfo3.ToString().Split(',');
            string[] Admin_roleInfo4 = listRole[0].roleInfo4.ToString().Split(',');
            string[] Admin_roleInfo5 = listRole[0].roleInfo5.ToString().Split(',');
            string[] Admin_roleInfo6 = listRole[0].roleInfo6.ToString().Split(',');
            for (int i = 0; i < Admin_roleInfo1.Count(); i++)
            {
                if (Admin_roleInfo1[0] == "1")
                {
                    ViewData["Admin_memberConsume"] = true;
                }
                if (Admin_roleInfo1[1] == "1")
                {
                    ViewData["Admin_memberRecharge"] = true;
                }
                if (Admin_roleInfo1[2] == "1")
                {
                    ViewData["Admin_memberAdd"] = true;
                }
                if (Admin_roleInfo1[3] == "1")
                {
                    ViewData["Admin_changeCardPwd"] = true;
                }
                if (Admin_roleInfo1[4] == "1")
                {
                    ViewData["Admin_memberSelect"] = true;
                }
                if (Admin_roleInfo1[5] == "1")
                {
                    ViewData["Admin_lostCard"] = true;
                }
                if (Admin_roleInfo1[6] == "1")
                {
                    ViewData["Admin_lock"] = true;
                }
                if (Admin_roleInfo1[7] == "1")
                {
                    ViewData["Admin_balanceRemind"] = true;
                }
                if (Admin_roleInfo1[8] == "1")
                {
                    ViewData["Admin_birthdayRemind"] = true;
                }
                if (Admin_roleInfo1[9] == "1")
                {
                    ViewData["Admin_userManager"] = true;
                }
                if (Admin_roleInfo1[10] == "1")
                {
                    ViewData["Admin_inputExcel"] = true;
                }
                if (Admin_roleInfo1[11] == "1")
                {
                    ViewData["Admin_email"] = true;
                }
            }

            for (int i = 0; i < Admin_roleInfo2.Count(); i++)
            {
                if (Admin_roleInfo2[0] == "1")
                {
                    ViewData["Admin_cardDesign"] = true;
                }
                if (Admin_roleInfo2[1] == "1")
                {
                    ViewData["Admin_memeberLevel"] = true;
                }
                if (Admin_roleInfo2[2] == "1")
                {
                    ViewData["Admin_Produce"] = true;
                }

            }
            for (int i = 0; i < Admin_roleInfo3.Count(); i++)
            {
                if (Admin_roleInfo3[0] == "1")
                {
                    ViewData["Admin_opeatorManager"] = true;
                }
                if (Admin_roleInfo3[1] == "1")
                {
                    ViewData["Admin_zhinengjuece"] = true;
                }
                if (Admin_roleInfo3[2] == "1")
                {
                    ViewData["Admin_roleManger"] = true;
                }

            }
            for (int i = 0; i < Admin_roleInfo4.Count(); i++)
            {
                if (Admin_roleInfo4[0] == "1")
                {
                    ViewData["Admin_consumerManager"] = true;
                }
                if (Admin_roleInfo4[1] == "1")
                {
                    ViewData["Admin_usergongxian"] = true;
                }
                if (Admin_roleInfo4[2] == "1")
                {
                    ViewData["Admin_goodsSelect"] = true;
                }
                if (Admin_roleInfo4[3] == "1")
                {
                    ViewData["Admin_memberCount"] = true;
                }
                if (Admin_roleInfo4[4] == "1")
                {
                    ViewData["Admin_ageAnalyse"] = true;
                }
                if (Admin_roleInfo4[5] == "1")
                {
                    ViewData["Admin_goodsPie"] = true;
                }

            }
            for (int i = 0; i < Admin_roleInfo5.Count(); i++)
            {
                if (Admin_roleInfo5[0] == "1")
                {
                    ViewData["Admin_systemLog"] = true;
                }
                if (Admin_roleInfo5[1] == "1")
                {
                    ViewData["Admin_userWater"] = true;
                }
                if (Admin_roleInfo5[2] == "1")
                {
                    ViewData["Admin_consumeWater"] = true;
                }
                if (Admin_roleInfo5[3] == "1")
                {
                    ViewData["Admin_goodsWater"] = true;
                }
                if (Admin_roleInfo5[4] == "1")
                {
                    ViewData["Admin_discountSelect"] = true;
                }

            }
            for (int i = 0; i < Admin_roleInfo6.Count(); i++)
            {
                if (Admin_roleInfo6[0] == "1")
                {
                    ViewData["Admin_card"] = true;
                }
                if (Admin_roleInfo6[1] == "1")
                {
                    ViewData["Admin_Acard"] = true;
                }
                if (Admin_roleInfo6[2] == "1")
                {
                    ViewData["Admin_wash"] = true;
                }
                if (Admin_roleInfo6[3] == "1")
                {
                    ViewData["Admin_delContent"] = true;
                }
            }

            #endregion
        }
    }
}
